<template>
    <Modal
            v-model="show"
            title="增加"
            @on-ok="save"
            @on-cancel="close"
    >
        <i-form ref="formFilter">
            <my-component></my-component>
            <form-item label="名称：">
                <i-input v-model="dto.name" placeholder="名称"/>
            </form-item>
            <form-item label="简介：">
                <i-input v-model="dto.description" placeholder="简介"/>
            </form-item>
            <form-item label="排序：">
                <i-input v-model="dto.sort" placeholder="排序"/>
            </form-item>
            <form-item label="图标：">
                <upload-image v-bind:upload-length="1" @uploadimg="uploadImg"></upload-image>
                <!--<i-input v-model="dto.ico" placeholder="图标"/>-->
            </form-item>
        </i-form>
    </Modal>
</template>

<script>
    module.exports = {
        props:["show","dto"],
        components: {
            'upload-image': httpVueLoader('upload-image.vue'),
        },
        data() {
            return {
                show:false,
                dto:{
                    id:undefined,
                    name:undefined,
                    ico:undefined,
                    description:undefined,
                    sort:undefined,
                    remark: undefined,
                }
            }
        },
        mounted() {
            console.info("添加数据组件加载成功",this.show)

        },
        methods:{
            close(){
                this.show=false;
                this.$emit("close",this.show);
            },
            uploadImg(img){
                console.info("上传成功：",img)
                this.dto.ico=img;
            },
            save() {
                let _this = this;
                _this.loading=true;
                ipost('/admin/category',
                    _this.dto,
                    successRes => {
                        console.info("加载成功sdgf：",successRes)
                        _this.dto=successRes.data;
                        _this.show=false;
                        this.$emit("save");
                    },failureRes => {
                        console.info("加载数据异常asdfg",failureRes)
                    }
                )
            },
        }
    }
</script>

<style>
    .hello {
        background-color: #ffe;
    }
</style>